package com.ruoyi.develop.factory.factoryProduceSaleAll.controller;

import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.develop.goodsSaledoGongxuUser.domain.GoodsSaledoGongxuUser;
import com.ruoyi.develop.goodsSaledoGongxuUser.service.IGoodsSaledoGongxuUserService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.develop.factory.factoryProduceSaleAll.domain.FactoryProduceSaleAll;
import com.ruoyi.develop.factory.factoryProduceSaleAll.service.IFactoryProduceSaleAllService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 生产订单和产品合计关联Controller
 * @author lmm
 * @date 2025-05-08
 */
@RestController
@RequestMapping("/factoryProduceSaleAll/factoryProduceSaleAll")
public class FactoryProduceSaleAllController extends BaseController {
    @Autowired
    private IFactoryProduceSaleAllService factoryProduceSaleAllService;
    @Autowired
    private IGoodsSaledoGongxuUserService goodsSaledoGongxuUserService;
    /**
     * 查询生产订单和产品合计关联列表
     */
//    @PreAuthorize("@ss.hasPermi('develop:FactoryProduceSaleAll:query')")
    @GetMapping("/list")
    public TableDataInfo list(FactoryProduceSaleAll entity) {
        startPage();
        List<FactoryProduceSaleAll> list = factoryProduceSaleAllService.selectList(entity);
        return getDataTable(list);
    }
    @GetMapping("/listByChild")
    public TableDataInfo listByChild(FactoryProduceSaleAll entity) {
        startPage();
        List<FactoryProduceSaleAll> list = factoryProduceSaleAllService.listByChild(entity);
        return getDataTable(list);
    }

    @GetMapping("/listTodo")
    public TableDataInfo listTodo(FactoryProduceSaleAll entity) {
        startPage();
        List<FactoryProduceSaleAll> list = factoryProduceSaleAllService.selectList(entity);
        return getDataTable(list);
    }

    /**
     * 导出生产订单和产品合计关联列表
     */
    @PreAuthorize("@ss.hasPermi('develop:FactoryProduceSaleAll:export')")
    @Log(title = "生产订单和产品合计关联", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, FactoryProduceSaleAll entity) {
        List<FactoryProduceSaleAll> list = factoryProduceSaleAllService.selectList(entity);
        ExcelUtil<FactoryProduceSaleAll> util = new ExcelUtil<FactoryProduceSaleAll>(FactoryProduceSaleAll. class);
        util.exportExcel(response, list, "生产订单和产品合计关联数据");
    }

    /**
     * 获取生产订单和产品合计关联详细信息
     */
    @PreAuthorize("@ss.hasPermi('develop:FactoryProduceSaleAll:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id) {
        return AjaxResult.success(factoryProduceSaleAllService.selectById(id));
    }

    /**
     * 新增生产订单和产品合计关联
     */
    @PreAuthorize("@ss.hasPermi('develop:FactoryProduceSaleAll:add')")
    @Log(title = "生产订单和产品合计关联", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    public AjaxResult add(@RequestBody FactoryProduceSaleAll entity) {
        return toAjax(factoryProduceSaleAllService.insert(entity));
    }

    @PostMapping("/insertTodo")
    public AjaxResult insertTodo(@RequestBody FactoryProduceSaleAll entity) {
        factoryProduceSaleAllService.insertTodo(entity);
        return AjaxResult.success("选择完成！");
    }

    @PostMapping("/insertTodoOther")
    public AjaxResult insertTodoOther(@RequestBody FactoryProduceSaleAll entity) {
        factoryProduceSaleAllService.insertTodoOther(entity);
        return AjaxResult.success("选择完成！");
    }
    /**
     * 修改生产订单和产品合计关联
     */
    @PreAuthorize("@ss.hasPermi('develop:FactoryProduceSaleAll:edit')")
    @Log(title = "生产订单和产品合计关联", businessType = BusinessType.UPDATE)
    @PutMapping("/edit")
    public AjaxResult edit(@RequestBody FactoryProduceSaleAll entity) {
        return toAjax(factoryProduceSaleAllService.update(entity));
    }

    /**
     * 删除生产订单和产品合计关联
     */
    @PreAuthorize("@ss.hasPermi('develop:FactoryProduceSaleAll:remove')")
    @Log(title = "生产订单和产品合计关联", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids) {
        return toAjax(factoryProduceSaleAllService.deleteByIds(ids));
    }
    @DeleteMapping("/deleteById/{id}")
    public AjaxResult deleteById(@PathVariable String id) {
        return toAjax(factoryProduceSaleAllService.deleteByIdAndChild(id));
    }

    @DeleteMapping("/deleteByIdOther/{id}")
    public AjaxResult deleteByIdOther(@PathVariable String id) {
        return toAjax(factoryProduceSaleAllService.deleteById(id));
    }
    @DeleteMapping("/removeNoTask/{id}")
    public AjaxResult removeNoTask(@PathVariable String id) {
        GoodsSaledoGongxuUser goodsSaledoGongxuUser=new GoodsSaledoGongxuUser();
        goodsSaledoGongxuUser.setSaleId(id);
        List<GoodsSaledoGongxuUser> goodsSaledoGongxuUsers=goodsSaledoGongxuUserService.selectList(goodsSaledoGongxuUser);
        if(goodsSaledoGongxuUsers.size()>0){
            return error("已分配任务不可修改");
        }
        return toAjax(factoryProduceSaleAllService.deleteByIdAndChild(id));
    }

    @GetMapping("/listFinishDoFactory")
    public TableDataInfo listFinishDoFactory(FactoryProduceSaleAll entity) {
        startPage();
        List<FactoryProduceSaleAll> list = factoryProduceSaleAllService.listFinishDoFactory(entity);
        return getDataTable(list);
    }

    //自制生产提交到质检（入库明细）
    @PostMapping("/insertRukuToZhijianRuku")
    public AjaxResult insertRukuToZhijianRuku(@Validated @RequestBody FactoryProduceSaleAll entity) {
        factoryProduceSaleAllService.insertRukuToZhijianRuku(entity);
        return AjaxResult.success("选择完成！");
    }

    //自制生产提交到质检
    @PostMapping("/insertRukuToZhijianFactory")
    public AjaxResult insertRukuToZhijianFactory(@Validated @RequestBody FactoryProduceSaleAll entity) {
        factoryProduceSaleAllService.insertRukuToZhijianFactory(entity);
        return AjaxResult.success("选择完成！");
    }

    @PreAuthorize("@ss.hasPermi('develop:FactoryProduceSaleAll:edit')")
    @Log(title = "生产订单和产品合计关联", businessType = BusinessType.UPDATE)
    @PutMapping("/editNotZizhi")
    public AjaxResult editNotZizhi(@RequestBody FactoryProduceSaleAll entity) {
        return toAjax(factoryProduceSaleAllService.editNotZizhi(entity));
    }

}
